#pragma once

#include <stdio.h>

void Print(int* array, int size)
{
  for(int i = 0; i < size; i++){
    printf("%d ", array[i]);
  }
  printf("\n");
}

void Swap(int* pa1, int* pa2)
{
  int tmp = *pa1;
  *pa1 = *pa2;
  *pa2 = tmp;
}

void SelectSort(int* array, int size)
{
  int left = 0;
  int right = size - 1;
  while(left <= right){
    int maxIndex = left;
    int minIndex = left;
    for(int i = left; i <= right; i++){
      if(array[i] > array[maxIndex]) maxIndex = i;
      if(array[i] < array[minIndex]) minIndex = i;
    }

    Swap(&array[left], &array[minIndex]);
    if(left == maxIndex) maxIndex = minIndex;
    Swap(&array[right], &array[maxIndex]);
    left++; right--;
  }
}
